<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a><cite>登记管理</cite></a>
    <a><cite>价格设置</cite></a>
  </div>
</div>

<script>
  var settings_url = 'agent-admin/registry/price_setting';
</script>
<script type="text/html" template lay-url="{{settings_url}}">
  <div class="layui-fluid layui-form">
    <div class="layui-form">
      {{# var settings = d.data }}
      <div class="layui-card">
        <div class="layui-card-header">
          通用设置
        </div>
        <div class="layui-card-body">
          <div class="layui-form-item">
            <label class="layui-form-label">默认价格</label>
            <div class="layui-input-inline">
              <input type="text" lay-verify="required" class="layui-input" autocomplete="off"
                     name="default_price" value="{{settings.default_price || ''}}">
            </div>
          </div>
        </div>
      </div>
      <div class="layui-card">
        <div class="layui-card-header">
          按作品类别设置 (未设置则使用默认价格）
        </div>
        <div class="layui-card-body">
          <table class="layui-table" style="width: 500px">
            <thead>
            <tr>
              <th style="width: 300px">作品类别</th>
              <th style="width: 200px">价格</th>
            </tr>
            </thead>
            <tbody>
            {{# layui.each(settings.per_category, function(index, item){ }}
            <tr>
              <td>{{item.name}}</td>
              <td>
                <div class="layui-inline">
                  <input type="number" name="prices[{{item.name}}]" class="layui-input"
                         value="{{item.price || ''}}" style="width: 100px">
                </div>
                <div class="layui-inline">
                  元/件
                </div>
              </td>
            </tr>
            {{# }) }}
            </tbody>
          </table>
        </div>

        <div style="margin-bottom: 60px"></div>
        <div class="layui-form-item">
          <div class="layui-footer">
            <div class="layui-input-block">
              <input type="button" lay-submit lay-filter="submit_settings" value="保存"
                     class="layui-btn">
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</script>
<script>
  layui.use([], function () {
    let form = layui.form
      , admin = layui.admin
    // 提交
    form.on('submit(submit_settings)', function (data) {
      let field = data.field;
      admin.post(settings_url, field, function () {
        layer.msg('保存成功', {
          offset: '15px'
          , icon: 1
          , time: 1000
        });
      });
    });
  });
</script>
